package com.bang.concurrency.example.threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @ClassName: ThreadPoolExample1
 * @Desc:  ExecutorService executorService = Executors.newCachedThreadPool();
 *         https://blog.csdn.net/pozmckaoddb/article/details/51478017
 * @auther: BANG
 * @Date: 2019/10/09 14:15
 * @Version: 1.0
 * @Modified By:
 */
@Slf4j
public class ThreadPoolExample1 {

    public static void main(String[] args) throws Exception {
//        ExecutorService executorService = Executors.newCachedThreadPool();
        ExecutorService executorService = myNewCache();

        log.info("创建线程池");
        for (int i = 0; i < 10; i++) {
            int index = i;
            executorService.execute(() -> {
                log.info("running {}", index);
            });
        }
    }

    public static ExecutorService myNewCache() {
        return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());
    }
}
